import com.zjq.pojo.*;
import com.zjq.service.BookService;
import com.zjq.service.OrderListService;
import com.zjq.service.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.awt.print.Book;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

public class test {
    ArrayList<List<Integer>> res = new ArrayList<List<Integer>>();
    ArrayList<Integer> list = new ArrayList<Integer>();

    @Test
    public void test4(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService books = (BookService) context.getBean("BookServiceImpl");
        List<Books> list = books.queryAllBook();
        for (Books book : list){
            System.out.println(book);
        }
    }

    @Test
    public void test(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookServiceImpl = (BookService) context.getBean("BookServiceImpl");
        Books booksBookKindMap = bookServiceImpl.queryBookById(1);
        System.out.println(booksBookKindMap);
    }

    @Test
    public void t10(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        OrderListService orderServiceImpl = (OrderListService)context.getBean("OrderListServiceImpl");
        List<Order> orders = orderServiceImpl.queryAllOrder();
        System.out.println(orders);
    }

    /*@Test
    public void test1(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookService = (BookService) context.getBean("BookServiceImpl");
        BigDecimal bigDecimal = (BigDecimal.valueOf(99));
        Books books = new Books(6,"Python",99,"从入门到秃头","akfj;ds",bigDecimal,3);
        bookService.addBook(books);

    }*/

   /* @Test
    public void test2(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookService = (BookService) context.getBean("BookServiceImpl");
        Books books = new Books(6,"Python",12,"从入门到秃头","akfj;ds",BigDecimal.valueOf(99),3);
        bookService.updateBook(books);
    }
*/
    @Test
    public void test3(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookService = (BookService) context.getBean("BookServiceImpl");
        bookService.deleteBookById(6);
    }

    @Test
    public void test5(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService bookService = (BookService) context.getBean("BookServiceImpl");
        List<Books> books = bookService.queryBookByKindId(2);
        for (Books book : books){
            System.out.println("==============="+book);
        }
    }

    @Test
    public void test6(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userServiceImpl = (UserService) context.getBean("UserServiceImpl");
        List<User> users = userServiceImpl.queryAllUser();
        for (User user : users){
            System.out.println(user);
        }
    }

    @Test
    public void test7(){
        System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    @Test
    public void test8(){
        int[] arr = {1,2,3,4};
        ArrayList<Integer> lst = new ArrayList<Integer>();
        for (int i=0;i<arr.length;i++){
            lst.add( arr[i]);
        }
        lst.remove(2);
        System.out.println();
    }

    @Test
    public void test9(){
        StringBuilder sb = new StringBuilder();
        sb.append("123");
        sb.append("321");
        System.out.println(sb);
        sb.delete(1,3);
        System.out.println(sb);
    }

    @Test
    public void test10(){
        int[] nums = {1,2,3};
        dfs(nums,0);
        System.out.println(res);
    }

    public void dfs(int[] nums,int index){
        if (index >= nums.length) return;

       for (int i = index;i < nums.length;i++){
           list.add(nums[i]);
           res.add(new ArrayList<Integer>(list));
           dfs(nums,i+1);
           list.remove(list.size()-1);
       }
    }

    @Test
    public void ts(){
        String str = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0;i < 6;i++){
            int i1 = random.nextInt(62);
            sb.append(str.charAt(i1));
        }
        System.out.println(sb);
    }

    @Test
    public void tt(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BookService boolServiceImpl = (BookService) context.getBean("BoolServiceImpl");
        Books books = boolServiceImpl.queryBookById(1);
        System.out.println(books);
    }

    @Test
    public void t1(){
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0;i < 10;i++){
            sb.append(random.nextInt(10));
        }
        int k = Integer.valueOf(String.valueOf(sb));
        System.out.println(k);
    }

    @Test
    public void t2(){
        int j = 0;
        //for (int i = 0;i < 10;i++){

            //System.out.print(j);
            //j++;
            //System.out.print(i);
            int i = 1;

            int s = ++i;

            int x= i++;
            System.out.print(i);
            System.out.print(s);

            System.out.print(x);

            int c = 0;
            int k = 5;
            c = k>>2;
        System.out.println("c"+c);
        //}
    }

    @Test
    public void sb(){
        for(int i = 0;i < 3;i++){
            for(int j = 3;j >= 0;j--){
                if (i == j){
                    continue;
                }
                System.out.println(i+" "+j);
            }
        }
    }
}
